package com.ym.controller.doctor.self;

import com.ym.common.constant.Constants;
import com.ym.core.annotation.ApiSign;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.entity.BankcardEntity;
import com.ym.medical.service.IBankcardSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(tags = "医生端-银行卡中心")
@RestController
@ApiSign
@RequestMapping(value = "/doctor/self/bankCard",headers = Constants.Api.VERSION)
public class DoctorBankCardController extends BaseController {
	private static final Logger LOGGER = LoggerFactory.getLogger(DoctorBankCardController.class);

	@Autowired
	private IBankcardSV bankCardSV;

	@Log
	@ApiOperation("保存银行卡")
	@PostMapping(value = "/insert", consumes = MediaType.APPLICATION_JSON_VALUE)
	public APIResponse<BankcardEntity> insertBankCard( @RequestBody BankcardEntity bankcard) {
		bankcard.setUserId(ShiroUtil.getLoginId());
		bankcard.setCreateTime(new Date());
		bankCardSV.insert(bankcard);
		return successData(bankcard);
	}

	@Log
	@ApiOperation("变更银行卡")
	@PostMapping(value = "/update", consumes = MediaType.APPLICATION_JSON_VALUE)
	public APIResponse<BankcardEntity> updateBankCard( @RequestBody BankcardEntity bankcard) {
	/*	Long currentUserId = getCurrentUser().getId();
		bankcard.setUserId(currentUserId);
		bankcard.setModifyTime(new Date());
		BankcardModel bankcardModel = new BankcardModel();
		bankcardModel.setQueryByWhereClause("where id=" + bankcard.getId() + " and user_id=" + currentUserId);
		bankCardSV.updateByModelSelective(bankcard, bankcardModel);*/
		bankcard.setModifyTime(new Date());
		bankCardSV.updateById(bankcard);
		return successData(bankcard);
	}
}
